@echo off
chcp 65001 > nul
echo ========================================
echo 启动所有服务（含知识库）
echo ========================================
echo.

REM 设置环境变量
set OH_CODE_PATH=%CD%\ohcode
set GLM_API_KEY=df6af53dd93b4afe9c1f0781f198305a.zcW6GYuBCOz3Xb27

echo 🔧 环境配置:
echo    OH_CODE_PATH = %OH_CODE_PATH%
echo.

echo ========================================
echo 【第1步】启动Gateway (8080)
echo ========================================
start "Gateway Service" cmd /k "cd gateway && mvn spring-boot:run"
echo ✓ Gateway启动中...
timeout /t 15 /nobreak > nul
echo.

echo ========================================
echo 【第2步】启动Knowledge Service (8087) ⭐ 重要
echo ========================================
start "Knowledge Service" cmd /k "cd openharmony-knowledge-service && mvn spring-boot:run"
echo ✓ Knowledge Service启动中...
echo    (首次启动可能需要1-2分钟)
timeout /t 20 /nobreak > nul
echo.

echo ========================================
echo 【第3步】启动LLM Service (8084)
echo ========================================
start "LLM Service" cmd /k "cd llm-service && mvn spring-boot:run"
echo ✓ LLM Service启动中...
timeout /t 15 /nobreak > nul
echo.

echo ========================================
echo 【第4步】启动Code Completion (8081)
echo ========================================
start "Code Completion" cmd /k "cd code-completion-service && mvn spring-boot:run"
echo ✓ Code Completion启动中...
timeout /t 15 /nobreak > nul
echo.

echo ========================================
echo 【第5步】启动Code Generation (8082)
echo ========================================
start "Code Generation" cmd /k "cd code-generation-service && mvn spring-boot:run"
echo ✓ Code Generation启动中...
timeout /t 15 /nobreak > nul
echo.

echo ========================================
echo 【第6步】启动Data Service (8083) - 可选
echo ========================================
start "Data Service" cmd /k "cd data-service && mvn spring-boot:run"
echo ✓ Data Service启动中...
timeout /t 10 /nobreak > nul
echo.

echo ========================================
echo 【第7步】启动Build Service (8085) - 可选
echo ========================================
start "Build Service" cmd /k "cd build-service && mvn spring-boot:run"
echo ✓ Build Service启动中...
echo.

echo ========================================
echo ✓ 所有服务启动完成！
echo ========================================
echo.
echo 📊 服务列表:
echo    Gateway:          http://localhost:8080
echo    Knowledge:        http://localhost:8087 ⭐
echo    LLM Service:      http://localhost:8084
echo    Code Completion:  http://localhost:8081
echo    Code Generation:  http://localhost:8082
echo    Data Service:     http://localhost:8083
echo    Build Service:    http://localhost:8085
echo.
echo 🔍 验证服务:
echo    curl http://localhost:8080/actuator/health
echo    curl http://localhost:8087/api/health
echo.
echo 📝 下一步:
echo    1. 等待所有服务启动完成（约2-3分钟）
echo    2. 运行知识库扫描: scan-ohcode.bat
echo    3. 在VS Code中测试插件功能
echo.

pause

